package cn.easybuy.web.backend;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.easybuy.entity.Product;
import cn.easybuy.entity.ProductCategory;
import cn.easybuy.service.ProductCategoryService;
import cn.easybuy.service.ProductService;
import cn.easybuy.service.impl.ProductCategoryServiceImpl;
import cn.easybuy.service.impl.ProductServiceImpl;
import cn.easybuy.util.Page;

import com.alibaba.fastjson.JSON;

public class MenberProductFenleiServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		PrintWriter out =response.getWriter();
		ProductCategoryService prService=new ProductCategoryServiceImpl();
		Page page =new Page();

			String currNo=request.getParameter("currNo");
			if (currNo==null||currNo=="") {
				currNo="1";
			}
			page.setCurrentPageNumber(Integer.parseInt(currNo));
			page.setPageSize(3);
			int totalCount=prService.totalCount();
			page.setTotalCount(totalCount);
			
			List<ProductCategory> list=prService.getProductCategories(Integer.parseInt(currNo), page.getPageSize());
			page.setProductCategoriesList(list);
			String listJson=JSON.toJSONString(page);
			out.print(listJson);
		
		out.flush();
		out.close();
	}
	

}
